
// 全局常量
const FIXEF_ATTR:i32 = 10_0000;
#[cfg(test)]
pub mod test_base {
    use super::dbase;

    #[test]
    fn tbase() {
        dbase();
    }
}
pub fn dbase() {

    // 不可变 通过let 重定义可重新赋值
    let _cover = 12;
    let _cover = 13;
    let _cover = _cover + 2;
    println!("cover is {}", _cover);
    println!("fixed attr is {}", FIXEF_ATTR);

    /*
     * 整数类型
     *  长度(bit)  带符号   无符号
     *      8      i8      u8
     *     16      i16     u16
     *     32      i32     u32
     *     64      i64     u64
     *    128      i128    u128
     *   arch      isize   usize
     * 
     * 整数字面值: 
     *   数制       示例           加类型后缀示例
     *  16进制      0xff            0xffu8
     *  10进制      10_0000         10_0000u8
     *   8进制      0o77            0o77u8
     *   2进制      0b0101_1010     0b0101_1010u8
     *  byte(u8)    b'A'            不支持
     */
    let hex8 = 0b0101_1010u8;
    let hex16 = 0xffu16;
    println!("hex8 = {}", hex8);
    println!("hex16 = {}", hex16);

    // 浮点类型: f32 f64
    let f3: f32 = 12.2;
    let f6: f64 = 125.1234;
    println!("f3 = {}", f3);
    println!("f6 = {}", f6);

    // 布尔: bool
    let t = true;
    let f: bool = false;
    println!("t = {}", t);
    println!("f = {}", f);

    // 字符: char
    let c1 = 'a';
    let c2 = '☆';
    let c3 = '✓';
    println!("c1 = {}", c1);
    println!("c2 = {}", c2);
    println!("c3 = {}", c3);

    // 元组
    let tup: (i32, u32, f32) = (12, 123, 12.1);
    println!("tup = ({} {} {})", tup.0, tup.1, tup.2);

    // 数组
    let arr1:[u32; 3] = [1, 2, 3];
    let arr2 = [1, 2, 3, 4, 5, 6, 7, 8, 9];
    println!("a[0] = {}", arr1[0]);
    println!("aa[7] = {}", arr2[7]);

    // 函数
    let fn1 = 32;
    print_a(fn1);

    let x1 = 12;
    let fn2 = {
        let x1 = 61;
        x1 + 100
    };
    println!("x1 = {}; fn2 = {}", x1, fn2); // 161

    // let fn3 = {
    //     let x1 = 61;
    //     x1 + 100; // -> ()
    // };
    // println!("fn3 = {}", fn3); // fn3 = ()

    let add = int_add(12, 22);
    println!("add = {}", add);

    if add < 34 {
        println!("add < 34");
    }else if add == 34 {
        println!("add == 34");
    } else {
        println!("add >= 34");
    }

    // if 是一个表达式， 可以放到“=”右边
    let add_ = if add %3 == 0 { "add % 3" } else { "add !% 3" };
    println!("add_ = {}", add_);

    let mut i = 0;
    let loopc = loop {
        i += 1;
        if i > 10 {
            break i * 2;
        }
    };
    println!("loopc = {}", loopc);

    while i < 30 {
        i += 1;
    }
    println!("while i = {}", i);

    // 遍历数组
    print!("arr2 = ");
    for ele in arr2.iter() {
        print!("{} ", ele);
    }
    println!();

    // range: 标准库提供, 指定 区间 [), rev()函数反转
    print!("1~19: ");
    for ele in (1..19).rev() {
        print!("{} ", ele);
    }
    println!();
}

fn print_a(a: i32) {
    println!("print_a -> a = {}", a);
}

fn int_add(a: i32, b: i32) -> i32 {
    a + b
}

// 接受固定长度数组
fn print_list(list: [i32; 10]) {

}

// 接受可变长度数组
fn print_list2(list: &[i32]) {

}